package com.czjtxy.extraTerm.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: staff-house
 * @author: MingYi
 * @create: 2021/07/04 20:46
 */
public class Util {
    public static int stringToInt(String s) {
        int num = 0;
        if (isStringNotNull(s)) {
            num = Integer.parseInt(s);
        }
        return num;
    }

    public static Date stringToDate(String s) {
        Date date = null;
        if (isStringNotNull(s)) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                date = sdf.parse(s);
                Long oneDay = Long.valueOf(1000 * 3600 * 24);
                date = new Date(date.getTime() + oneDay);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return date;
    }

    public static boolean isStringNotNull(String str) {
        return str != null && !"".equals(str);
    }

    public static String likeStr(String str) {
        return "%" + str + "%";
    }
}
